import 'dart:convert';
import 'package:isolate/isolate.dart';

class Transformer {
  static Future<LoadBalancer> loadBalancer =
      LoadBalancer.create(2, IsolateRunner.spawn);

  static dynamic _transformer(dynamic jsonStr) {
    try {
      return jsonDecode(jsonStr);
    } catch (e) {
      throw e;
    }
  }

  static Future<dynamic> transformer(dynamic jsonStr) async {
    final lb = await loadBalancer;
    return lb.run<dynamic, dynamic>(_transformer, jsonStr);
  }
}
